<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>新增用户</title>
</head>
<body>
<h1>新增用户</h1>
<form th:action="@{/users}" th:object="${user}" method="post">
    <div>
        <label>姓名：</label>
        <input type="text" th:field="*{name}" />
        <!-- 显示验证错误信息 -->
        <span th:if="${#fields.hasErrors('name')}" th:errors="*{name}" style="color: red;"></span>
    </div>
    <div>
        <label>邮箱：</label>
        <input type="email" th:field="*{email}" />
        <span th:if="${#fields.hasErrors('email')}" th:errors="*{email}" style="color: red;"></span>
    </div>
    <div>
        <label>年龄：</label>
        <input type="number" th:field="*{age}" />
        <span th:if="${#fields.hasErrors('age')}" th:errors="*{age}" style="color: red;"></span>
    </div>
    <div>
        <button type="submit">保存</button>
        <a th:href="@{/users}">取消</a>
    </div>
</form>
</body>
</html>